package com.lagou.web.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.lagou.service.HelloService;
import com.lagou.service.HiService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ascetic
 * @version 1.0
 * @ClassName DubboConfig
 * @Description TODO
 * @date 2020-07-13 14:35
 */
@Configuration
public class DubboConfig {
    @Bean
    public ApplicationConfig applicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("service-web");
        return applicationConfig;
    }

    //<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"></dubbo:registry>
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("127.0.0.1:2181");
        return registryConfig;
    }

    @Bean
    public ReferenceConfig<HelloService> helloReferenceConfig() {
        ReferenceConfig<HelloService> serviceConfig = new ReferenceConfig<>();
        serviceConfig.setInterface(HelloService.class);
        serviceConfig.setTimeout(5000);
        serviceConfig.setVersion("*");
        serviceConfig.setRetries(3);
        serviceConfig.setLoadbalance("roundrobin");
        return serviceConfig;
    }

    @Bean
    public ReferenceConfig<HiService> hiReferenceConfig() {
        ReferenceConfig<HiService> serviceConfig = new ReferenceConfig<>();
        serviceConfig.setInterface(HiService.class);
        serviceConfig.setTimeout(5000);
        serviceConfig.setVersion("*");
        serviceConfig.setRetries(3);
        serviceConfig.setLoadbalance("roundrobin");
        return serviceConfig;
    }


    @Bean
    public ConsumerConfig consumerConfig() {
        ConsumerConfig consumerConfig = new ConsumerConfig();
        consumerConfig.setCheck(false);
        consumerConfig.setTimeout(5000);
        consumerConfig.setFilter("transPortIPFilter");
        return consumerConfig;
    }

}